from tidy_core.load_cmd import parse_cmd
from tidy_core.load_config import Config


def combine_config(config):
    config_dict = config.parse_config()
    cmd_dict = parse_cmd(config_dict)
    key_rules = dict([ (template_key, False)  for template_key in config.config_template_dict['key_rules'].keys()])

    for cmd_key in cmd_dict.keys():
        key_detail_info = cmd_key.split(":")
        if len(key_detail_info) > 1:
            key_group = key_detail_info[0]
            if key_rules[key_group]:
                print(f"option error: you have selected same group {key_group}, {cmd_key} option, it must be choose one. ")
                return None
            key_rules[key_group] = True

        config_dict[cmd_key] = cmd_dict[cmd_key]

    return config_dict


